package com.badibadi.fragment;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebViewClient;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.ZoomButtonsController;

import com.amap.api.maps2d.AMap;
import com.amap.api.maps2d.MapView;
import com.amap.api.maps2d.AMap.InfoWindowAdapter;
import com.amap.api.maps2d.AMap.OnInfoWindowClickListener;
import com.amap.api.maps2d.AMap.OnMarkerClickListener;
import com.amap.api.maps2d.model.LatLng;
import com.amap.api.maps2d.model.Marker;
import com.android.volley.toolbox.NetworkImageView;
import com.badibadi.activity.ActivityOverViewActivity;
import com.badibadi.activity.ActivityReadingActivity;
import com.badibadi.activity.ClubHomepageActivity;
import com.badibadi.activity.IndexActivity;
import com.badibadi.activity.MyDataActivity;
import com.badibadi.activity.PinyinSeeActivityTheOriginatorLookParticipantsActivity;
import com.badibadi.activity.SeeOtherPeopleSpaceActivity;
import com.badibadi.adapter.PinLunGYAdapter;
import com.badibadi.adapter.PinLunGYAdapter.PinLunInterface;
import com.badibadi.fragment.ActivityReadingOffLineFragment.ViewHolder;
import com.badibadi.fragment.ActivityReadingOffLineFragment.getEditText;
import com.badibadi.fragment.ActivityReadingOffLineFragment.setActivityView;
import com.badibadi.infos.ActivityReadingModel;
import com.badibadi.infos.ClueTypeModel;
import com.badibadi.infos.Discuss;
import com.badibadi.infos.Results;
import com.badibadi.mytools.AMapUtils;
import com.badibadi.mytools.CalendarTools;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.Dialog;
import com.badibadi.mytools.DisplayUtil;
import com.badibadi.mytools.EditTextTools;
import com.badibadi.mytools.HtmlUtils;
import com.badibadi.mytools.MyThreadTool;
import com.badibadi.mytools.ShareSDKTools;
import com.badibadi.mytools.Utils;
import com.badibadi.mytools.VolleyTools;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.SinaExpressionActivity;
import com.libjph.util.JsonUtil;
import com.libjph.util.StringUtil;
//import com.lidroid.xutils.util.LogUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.view.my_view.MyWebView_ShowAll;

//ShareSDK send fragment_online_activity_reading ll_share  startTimeAddEndTime ll_share introduce activity_canjiazhe nickName
public class ActivityReadingOnLineFragment extends BaseFragment implements
		OnClickListener {
	
	EditTextTools et_tools;
	PinLunGYAdapter gyAdapter;
	protected static final String TAG = "ActivityReadingOffLineFragment";

	private DisplayImageOptions options;

	static ActivityReadingOffLineFragment fragment;
	// 获取网络数据相关
	private ActivityReadingModel activityReadingModel;
	private String actId;
	private String activity_faqi_uid;// 活动发起者的id
	private String cid;// 俱乐部id，用于分享
	private String l;
	// bundle.putInt("activityRootView", R.id.activityRootView);
	// // 地图相关
	// private MapView mapView;
	// private AMap aMap;
	private ViewHolder holder;
	// 数据
	private String names = null;
	// 下面是评论的
	private Discuss discuss;
	// private ShowDisscussModel showDisscuss;

	private Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {

			switch (msg.what) {
			case 1:

				try {
					Utils.ExitPrgress(getActivity());
					Utils.showMessage(getActivity(),
							getResources().getString(R.string.l_net_error));
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 2:
				try {
					Utils.ExitPrgress(getActivity());
					initView();
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 3:
				try {
					Utils.ExitPrgress(getActivity());
					Utils.showMessage(getActivity(),
							getResources().getString(R.string.l_xb12));
				} catch (Exception e) {

				}
				break;
			case 4:// 这是评论的
				try {
					Utils.ExitPrgress(getActivity());
					initDissCussView();
				} catch (Exception e) {
					// TODO: handle exception
				}
				// try {

				// } catch (Exception e) {
				// // TODO: handle exception
				// }
				break;
			case 5:// 评论成功

				try {
					Utils.ExitPrgress(getActivity());
					Utils.showMessage(
							getActivity(),
							getResources().getString(
									R.string.wx_pinglun_success));
					// Intent intent=new
					// Intent(getActivity(),LogReadingDanjiActivity.class);
					// // bun.putString("aid", aid);
					// // bun.putInt("position", position);
					// // bun.putString("rid", rid);
					// intent.put("aid", value);
					// intent.put("position",position);
					ShowActivity();

				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 6:// 评论成功
				Utils.ExitPrgress(getActivity());
				try {
					Utils.showMessage(getActivity(),
							getResources().getString(R.string.wx_pinglun_false));
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 7:// 点赞成功
				Utils.ExitPrgress(getActivity());
				try {
					Utils.showMessage(getActivity(),
							getResources().getString(R.string.wx_zan_success));
					holder.iv_zan.setSelected(true);
					holder.admire.setText(""
							+ (Integer.parseInt(holder.admire.getText()
									.toString() + 1)));
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			case 8:// 点赞失败
				Utils.ExitPrgress(getActivity());
				try {
					Utils.showMessage(getActivity(),
							getResources().getString(R.string.wx_txt_50));
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;
			// case 9://软键盘开
			// keyOpen=true;
			// break;
			// case 10://软键盘关
			// keyOpen=false;
			// break;
			// default:
			// break;
			}
		}

	};

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		// bundle.putInt("activityRootView", R.id.activityRootView);
		// activiytRootView=getArguments().getInt("activityRootView");
		options = new DisplayImageOptions.Builder()
				.showStubImage(R.drawable.ic_stub)
				.showImageForEmptyUri(R.drawable.noimage)
				.showImageOnFail(R.drawable.noimage).cacheInMemory()
				.cacheOnDisc().displayer(new RoundedBitmapDisplayer(5)).build();
		try {
			actId = getArguments().getString("actId");
			activity_faqi_uid = getArguments().getString("fq_uid");
		} catch (Exception e) {
			// actId = "6";
		}
		cid = getArguments().getString("cid", "0");
		ShowActivity();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.fragment_online_activity_reading,
				null);
		LinearLayout activity_model = (LinearLayout) view
				.findViewById(R.id.activity_model);

		initViewID(view);
		// mapView = (MapView) view.findViewById(R.id.map);
		// mapView.onCreate(savedInstanceState);// 此方法必须重写

		// init(view);

		return view;
	}

	/**
	 * 初始化界面上除了地图的所有id
	 * 
	 * @param view
	 */
	private void initViewID(View view) {
		// TODO Auto-generated method stub
		holder = new ViewHolder();
		holder.activity_canjiazhe = (LinearLayout) view
				.findViewById(R.id.activity_canjiazhe);

		holder.head = (ImageView) view.findViewById(R.id.head);
		holder.nickName = (TextView) view.findViewById(R.id.nickName);
		holder.startTimeAddEndTime = (TextView) view
				.findViewById(R.id.startTimeAddEndTime);
		// holder.address = (TextView) view.findViewById(R.id.address);
		// holder.limit = (TextView) view.findViewById(R.id.limit);
		// holder.gold = (TextView) view.findViewById(R.id.gold);
		// holder.organization = (TextView)
		// view.findViewById(R.id.organization);
		// holder.organization_introduce = (TextView) view
		// .findViewById(R.id.organization_introduce);
		holder.introduce = (MyWebView_ShowAll) view
				.findViewById(R.id.introduce);
		holder.iv_zan = (ImageView) view.findViewById(R.id.zan);

		// 以下是评论的
		holder.admire = (TextView) view.findViewById(R.id.admire);
		holder.discuss = (TextView) view.findViewById(R.id.discuss);
		holder.share = (TextView) view.findViewById(R.id.share);
		holder.zanPeople = (TextView) view.findViewById(R.id.zanPeople);
		holder.listview_pinlun = (ListView) view
				.findViewById(R.id.listview_pinlun);
		// holder.delete=(TextView)view.findViewById(R.id.delete);
		holder.send_content = (EditText) view.findViewById(R.id.send_content);
		holder.send = (Button) view.findViewById(R.id.send);
		// holder.lshare=(ImageView)view.findViewById(R.id.ll_share);
		holder.all_zan_people = (LinearLayout) view
				.findViewById(R.id.all_zan_people);
		holder.ll_share = (LinearLayout) view.findViewById(R.id.ll_share);

		holder.tuxian1 = (ImageView) view.findViewById(R.id.tuxian1);
		holder.biaoqing = (ImageView) view.findViewById(R.id.biaoqing);

		holder.typeName = (TextView) view.findViewById(R.id.typeName);
		holder.clubName = (TextView) view.findViewById(R.id.clubName);
		holder.h_activity_canjiazhe = (LinearLayout) view
				.findViewById(R.id.h_activity_canjiazhe);
		holder.tiaozhuantype=(LinearLayout)view.findViewById(R.id.tiaozhuantype);
	
	}

	class ViewHolder {
		public LinearLayout h_activity_canjiazhe;
		public LinearLayout tiaozhuantype;
		public ImageView tuxian1;
		public LinearLayout ll_share;
		public ImageView iv_zan;
		public LinearLayout all_zan_people;
		public ImageView lshare;
		public Button send;
		public EditText send_content;
		public GridView picture_gridView;
		public ListView listview_pinlun;
		public TextView zanPeople;
		public TextView share;
		public TextView discuss;
		public TextView admire;
		public MyWebView_ShowAll introduce;
		// public TextView organization_introduce;
		// public TextView organization;
		// public TextView gold;
		// public TextView limit;
		// public TextView address;
		public TextView startTimeAddEndTime;
		public TextView nickName;
		public ImageView head;
		public LinearLayout activity_canjiazhe;
		public ImageView biaoqing;
		public TextView typeName;
		public TextView clubName;

	}

	/**
	 * 显示获取的数据
	 */
	private void initView() {
		// TODO Auto-generated method stub

		if (activityReadingModel.getTypeName() != null)
			holder.typeName.setText(""
					+ activityReadingModel.getTypeName().getName());

		holder.biaoqing.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getActivity(),
						SinaExpressionActivity.class);
				// ((Activity)(getActivity()))
				getActivity().startActivityForResult(intent,
						PinLunGYAdapter.BIAO_QING);
			}
		});

		// 分享
		holder.ll_share.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (!Utils.getUid(getActivity()).equals("")) {
					if (!StringUtil.isNullOrEmpty(activityReadingModel
							.getIntroduce()))
						if (activityReadingModel.getIntroduce().length() >= 120) {
							String content = activityReadingModel
									.getIntroduce().substring(0, 120) + "...";
							if (!StringUtil.isNullOrEmpty(activityReadingModel
									.getImage())) {
								ShareSDKTools.ShowOneKeyShare(
										getActivity(),
										"分享",
										content,
										"",
										Constants.BadiDownImgUrl
												+ "/"
												+ activityReadingModel
														.getImage(),
										"activity",
										activityReadingModel.getId(),
										activityReadingModel.getUid(), cid,
										"activity");
							} else {
								ShareSDKTools.ShowOneKeyShare(getActivity(),
										"分享", content, "", "", "activity",
										activityReadingModel.getId(),
										activityReadingModel.getUid(), cid,
										"activity");
							}

						} else {

							String content = activityReadingModel
									.getIntroduce();
							if (!StringUtil.isNullOrEmpty(activityReadingModel
									.getImage())) {
								ShareSDKTools.ShowOneKeyShare(
										getActivity(),
										"分享",
										content,
										"",
										Constants.BadiDownImgUrl
												+ "/"
												+ activityReadingModel
														.getImage(),
										"activity",
										activityReadingModel.getId(),
										activityReadingModel.getUid(), cid,
										"activity");
							} else {
								ShareSDKTools.ShowOneKeyShare(getActivity(),
										"分享", content, "", "", "activity",
										activityReadingModel.getId(),
										activityReadingModel.getUid(), cid,
										"activity");
							}

						}
				} else {
					Utils.showMessage(getActivity(),
							getResources().getString(R.string.l_xb10));
				}
			}
		});
		// 是否已经赞过
		if (activityReadingModel.getIs_praised().equals("1")) {
			holder.iv_zan.setSelected(true);
		} else// 0
		{
			holder.iv_zan.setSelected(false);
			// 点赞
			holder.iv_zan.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					if (!Utils.getUid(getActivity()).equals("")) {
						dianzan(getActivity(), Utils.getUid(getActivity()),
								activityReadingModel.getId(),
								activityReadingModel.getUid(), "activity", 7, 8);
					} else {
						Utils.showMessage(getActivity(), getResources()
								.getString(R.string.l_xb10));
					}
				}
			});
		}

		// // 发送
		// holder.send.setOnClickListener(new View.OnClickListener() {
		//
		// @Override
		// public void onClick(View v) {
		// // TODO Auto-generated method stub
		// String content = holder.send_content.getText().toString()
		// .trim();
		// String b_uid = activityReadingModel.getUid();// 活动发起者的id
		// sendMessage(Utils.getUid(getActivity()), b_uid,
		// activityReadingModel.getId(), "activity", content);
		// }
		// });

		// // 判断经纬度是否合法
		// if (activityReadingModel.getMap_x() != null
		// && activityReadingModel.getMap_y() != null) {
		// if (AMapUtils.LatitudeAndLongItudeIsLegal(
		// Double.parseDouble(activityReadingModel.getMap_x()),
		// Double.parseDouble(activityReadingModel.getMap_y()))) {
		// LatLng latlng = new LatLng(
		// Double.parseDouble(activityReadingModel.getMap_x()),
		// Double.parseDouble(activityReadingModel.getMap_y()));
		// AMapUtils.drawMarker(aMap, "" + 0, "", latlng);
		// AMapUtils.CameraMoveTo(aMap, latlng);
		// }
		// }
		// 参加者
		for (int i = 0; i < activityReadingModel.getUser().size(); i++) {
			if (activityReadingModel.getUser() != null)
				holder.activity_canjiazhe.addView(addHead(activityReadingModel
						.getUser().get(i).getHead()));
		}
		holder.h_activity_canjiazhe.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (!Utils.getUid(getActivity()).equals("")) {
					Intent intent = new Intent(
							getActivity(),
							PinyinSeeActivityTheOriginatorLookParticipantsActivity.class);
					intent.putExtra("aid", actId);
					intent.putExtra("fq_uid", activity_faqi_uid);
					startActivity(intent);
				} else {
					Utils.showMessage(getActivity(),
							getResources().getString(R.string.l_xb10));
				}
			}
		});
		holder.activity_canjiazhe.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (!Utils.getUid(getActivity()).equals("")) {
					Intent intent = new Intent(
							getActivity(),
							PinyinSeeActivityTheOriginatorLookParticipantsActivity.class);
					intent.putExtra("aid", actId);
					intent.putExtra("fq_uid", activity_faqi_uid);
					startActivity(intent);
				} else {
					Utils.showMessage(getActivity(),
							getResources().getString(R.string.l_xb10));
				}
			}
		});
		names = activityReadingModel.getNames();
		// 活动发起者
		if (activityReadingModel.getUser() != null) {
			try {
				ImageLoader.getInstance().displayImage(
						Constants.BadiDownImgUrl
								+ "/"
								+ activityReadingModel.getUser().get(0)
										.getHead(), holder.head, options);
				holder.head.setOnClickListener(new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						if (!Utils.getUid(getActivity()).equals("")) {
							if (activityReadingModel.getUser().get(0).getId()
									.equals("" + Utils.getUid(getActivity()))) {
								Intent intent = new Intent(getActivity(),
										MyDataActivity.class);
								startActivity(intent);
							} else {
								Intent intent = new Intent(getActivity(),
										SeeOtherPeopleSpaceActivity.class);
								intent.putExtra("friend_id",
										activityReadingModel.getUser().get(0)
												.getId());
								startActivity(intent);
							}
						} else {
							Utils.showMessage(getActivity(), getResources()
									.getString(R.string.l_xb10));
						}
					}
				});
			} catch (Exception e) {
				// TODO: handle exception
			}
			try {
				holder.nickName.setText(""
						+ activityReadingModel.getUser().get(0).getNickName());
				holder.nickName.setOnClickListener(new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						if (!Utils.getUid(getActivity()).equals("")) {
							if (activityReadingModel.getUser().get(0).getId()
									.equals("" + Utils.getUid(getActivity()))) {
								Intent intent = new Intent(getActivity(),
										MyDataActivity.class);
								startActivity(intent);
							} else {
								Intent intent = new Intent(getActivity(),
										SeeOtherPeopleSpaceActivity.class);
								intent.putExtra("friend_id",
										activityReadingModel.getUser().get(0)
												.getId());
								startActivity(intent);
							}
						} else {
							Utils.showMessage(getActivity(), getResources()
									.getString(R.string.l_xb10));
						}
					}
				});

			} catch (Exception e) {
				// TODO: handle exception
			}
		}
		//活动类别跳转
		try {
			holder.tiaozhuantype.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					Intent intent = new Intent(getActivity(),
							ActivityOverViewActivity.class);
//					intent.putExtra("Type",
//							activityReadingModel.getTypeName()
//									);
//					intent.putExtra("type", "huodong");
//					intent.putExtra("type_id",
//							activityReadingModel.getTypeid()
//									);
//					intent.putExtra("tid",
//							activityReadingModel.getTypeid()
//									);
//					 List<ClueTypeModel> clueTypeModels = null;
//					ClueTypeModel cc = new ClueTypeModel();
//					cc.setId(activityReadingModel.getTypeid());
//					cc.setName("社交");
					/* List<ClueTypeModel> clueTypeModels;
					intent.putExtra("CalendarActivity",
							clueTypeModels.get(activityReadingModel.getTypeid()));*/
					startActivity(intent);
					
					
				}
			});
		} catch (Exception e) {
			// TODO: handle exception
		}
		// 开始和结束时间
		String start = CalendarTools.getFormatTime(Double
				.parseDouble(activityReadingModel.getStart_time() + "000"),
				"yyyy.MM.dd HH:mm");
		String end = CalendarTools.getFormatTime(
				Double.parseDouble(activityReadingModel.getEnd_time() + "000"),
				"yyyy.MM.dd HH:mm");

		holder.startTimeAddEndTime.setText(start + "  -  " + end);
		// // 活动地址
		// holder.address.setText("" + activityReadingModel.getAddress());
		// // 限制人数
		// if (activityReadingModel.getIs_limit().equals("1")) {
		// holder.limit.setText("限额" + activityReadingModel.getLimit() + "人");
		// } else {
		// holder.limit.setText("无限制");
		// }
		// // 金币数量
		// if (activityReadingModel.getIs_gold().equals("1")) {
		// holder.gold.setText("金币" + activityReadingModel.getGold() + "枚");
		// } else {
		// holder.gold.setText("无需金币");
		// }
		// // 发起组织
		// if
		// (!StringUtil.isNullOrEmpty(activityReadingModel.getOrganization())) {
		// holder.organization.setText(""
		// + activityReadingModel.getOrganization());
		// } else {
		// holder.organization.setText("无");
		// }
		// // 发起组织简介
		// if (!StringUtil.isNullOrEmpty(activityReadingModel
		// .getOrganization_introduce())) {
		// holder.organization_introduce.setText(""
		// + activityReadingModel.getOrganization_introduce());
		// } else {
		// holder.organization_introduce.setText("无");
		// }
		// introduce活动简介
		if (!StringUtil.isNullOrEmpty(activityReadingModel.getIntroduce())) {

			String con = activityReadingModel.getIntroduce();
			con = Utils.getContent(con);
//			LogUtils.d("con=" + con);
			// new HtmlUtils(getActivity(), holder.introduce,
			// con).showTextView();
			// holder.introduce.setText("" +
			// activityReadingModel.getIntroduce());
			// holder.introduce.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
			// WebSettings webSettings = holder.introduce.getSettings();
			// webSettings.setJavaScriptEnabled(true);
			// // webSettings.setBuiltInZoomControls(true);
			// webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
			// setZoomControlGone(holder.introduce);
			// holder.introduce.getSettings().setDefaultTextEncodingName("UTF-8");
			// holder.introduce.loadData(
			// Is_Tu(activityReadingModel.getIntroduce()),
			// "text/html;charset=UTF-8", null);
			holder.introduce.getSettings().setJavaScriptEnabled(true);
			holder.introduce.getSettings().setDomStorageEnabled(true);
			holder.introduce.getSettings().setUseWideViewPort(true);
			holder.introduce.getSettings().setLoadWithOverviewMode(true);

			holder.introduce.getSettings().setBuiltInZoomControls(false);// 会出现放大缩小的按钮
			holder.introduce.loadUrl(activityReadingModel.getUrl());
			holder.introduce.setWebViewClient(new myWebViewClient());
			// holder.introduce.setOnTouchListener(new OnTouchListener()
			// {//根据手势缩放webview
			// private float OldX1, OldY1, OldX2, OldY2;
			// private float NewX1, NewY1, NewX2, NewY2;
			//
			// @Override
			// public boolean onTouch(View v, MotionEvent event) {
			// // TODO Auto-generated method stub
			// switch (event.getAction()) {
			// case MotionEvent.ACTION_POINTER_2_DOWN:
			// if (event.getPointerCount() == 2) {
			// OldX1 = event.getX(0);
			// OldY1 = event.getY(0);
			// OldX2 = event.getX(1);
			// OldY2 = event.getY(1);
			// }
			// break;
			// case MotionEvent.ACTION_MOVE:
			// if (event.getPointerCount() == 2) {
			// if (OldX1 == -1 && OldX2 == -1)
			// break;
			// NewX1 = event.getX(0);
			// NewY1 = event.getY(0);
			// NewX2 = event.getX(1);
			// NewY2 = event.getY(1);
			// float disOld = (float) Math.sqrt((Math.pow(OldX2
			// - OldX1, 2) + Math.pow(OldY2 - OldY1, 2)));
			// float disNew = (float) Math.sqrt((Math.pow(NewX2
			// - NewX1, 2) + Math.pow(NewY2 - NewY1, 2)));
			//    
			// + disNew);
			// if (disOld - disNew >= 25) {
			// // 缩小
			// holder.introduce.zoomOut();
			// // holder.introduce.loadUrl("javascript:mapScale=1;");
			//    
			// } else if (disNew - disOld >= 25) {
			// // 放大
			// holder.introduce.zoomIn();
			// // holder.introduce.loadUrl("javascript:mapScale=-1;");
			//    
			// }
			// OldX1 = NewX1;
			// OldX2 = NewX2;
			// OldY1 = NewY1;
			// OldY2 = NewY2;
			// }
			// break;
			// case MotionEvent.ACTION_UP:
			// if (event.getPointerCount() < 2) {
			// OldX1 = -1;
			// OldY1 = -1;
			// OldX2 = -1;
			// OldY2 = -1;
			// }
			// break;
			// }
			// return false;
			// }
			// });
		} else {
			// holder.introduce.setText("无");
		}

		// 显示评论all_zan_people
		holder.admire.setText("" + activityReadingModel.getAdmire());
		// 显示评论
		holder.discuss.setText("" + activityReadingModel.getDiscuss());
		// 分享
		holder.share.setText("" + activityReadingModel.getShare());

		if (activityReadingModel.getPraisedUserInfo() != null) {
			String zanpeople = "";
			StringBuffer buff = null;
			int zishu = 0;// 统计字数,是为了知道什么地方变色
			for (int i = 0; i < activityReadingModel.getPraisedUserInfo()
					.size(); i++) {
				// zanPeople
				buff = new StringBuffer("");
				buff.append("、"
						+ activityReadingModel.getPraisedUserInfo().get(i)
								.getNickName());
				if (i > 10) {
					zishu = buff.length() - 1;
					buff.append(getResources().getString(R.string.l_xb84)
							+ activityReadingModel.getPraisedUserInfo().size()
							+ getResources().getString(R.string.l_xb85));
					break;
				}
				if (i == activityReadingModel.getPraisedUserInfo().size() - 1) {
					zishu = buff.length() - 1;
					buff.append(getResources().getString(R.string.l_xb86));
				}

			}
			zanpeople = buff.substring(1, buff.length());
			SpannableStringBuilder style = new SpannableStringBuilder(zanpeople);
			style.setSpan(
					new ForegroundColorSpan(getResources().getColor(
							R.color.gray_445879)), 0, zishu,
					Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
			holder.zanPeople.setText(style);
		} else {
			holder.all_zan_people.setVisibility(View.GONE);
		}

		try {
			holder.clubName.setText(activityReadingModel.getC_name());
			holder.clubName.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
//					if (!Utils.getUid(getActivity()).equals("")) {
						Intent intent = new Intent(getActivity(),
								ClubHomepageActivity.class);
						intent.putExtra("cid", activityReadingModel.getCid());
						intent.putExtra("c_uid",
								activityReadingModel.getC_uid());
						if (activityReadingModel.getIsJoinClub() != null) {
							// if (activityReadingModel.getIsJoinClub()
							// .equals("false")) {
							// intent.putExtra("is_join", "0");
							// } else if
							// (activityReadingModel.getIsJoinClub().equals(
							// "true")) {
							intent.putExtra("is_join", "1");
							// }
						} else {
							intent.putExtra("is_join", "0");
						}
						intent.putExtra("logo", activityReadingModel.getLogo());
						startActivity(intent);
//					} else {
//						Utils.showMessage(getActivity(), getResources()
//								.getString(R.string.l_xb10));
//					}
				}
			});
		} catch (Exception e) {
			// TODO: handle exception
		}

		// String text = String.format(
		// getResources().getString(R.string.fqcjlcyyjtpx), money);
		// SpannableStringBuilder style = new SpannableStringBuilder(text);
		// // 设置指定位置文字的颜色
		// style.setSpan(new ForegroundColorSpan(Color.BLUE), 10,
		// (10 + ("" + money).length()),
		// Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
		// fqcj.setText(style);
		// String a = buff.substring(1, buff.length());

		// holder.zanPeople.setText("" + a);
		holder.tuxian1.setSelected(true);

		String l = Dialog.getSystemLanguageTypegy(getActivity());
		ShowDisscuss(activityReadingModel.getId(), "activity", "99999", l);
//		   

	}

	private class myWebViewClient extends WebViewClient {

		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			// TODO Auto-generated method stub
			return super.shouldOverrideUrlLoading(view, url);
		}

	}

	public void setZoomControlGone(View view) {
		Class classType;
		Field field;
		try {
			classType = WebView.class;
			field = classType.getDeclaredField("mZoomButtonsController");
			field.setAccessible(true);
			ZoomButtonsController mZoomButtonsController = new ZoomButtonsController(
					view);
			mZoomButtonsController.getZoomControls().setVisibility(View.GONE);
			try {
				field.set(view, mZoomButtonsController);
			} catch (IllegalArgumentException e) {
				   
			} catch (IllegalAccessException e) {
				   
			}
		} catch (SecurityException e) {
			   
		} catch (NoSuchFieldException e) {
			   
		}
	}

	/**
	 * 返回网页数据中是否有图片数据，有的话进行处理
	 * 
	 * @param d
	 * @return
	 */
	private String Is_Tu(String d) {
		if (d != null) {
			String dd1[] = d.split("src=\"");
			if (dd1 != null && dd1.length > 1) {
				// String fanhui = "";
				for (int i = 1; i < dd1.length; i++) {
					String dd2[] = dd1[i].split("\" alt");
					if (dd2 != null && dd2.length > 0) {
						if (Is_Biaoqing(dd2[0])) {
							d = d.replace(dd2[0], Constants.BadiWebImgUrl
									+ dd2[0]);
						}
					}
				}
				return d;
			} else {
				return d;
			}
		} else {
			return "";
		}
	}

	/**
	 * 判断图片是否是表情
	 * 
	 * @param d
	 * @return
	 */
	private boolean Is_Biaoqing(String d) {

		String string = d;
		String sub = "http://";
		int a = string.indexOf(sub);
		if (a >= 0) {
			return false;
		} else {
			return true;
		}
	}

	/**
	 * 用户评论使用接口 提交方式GET
	 * 
	 * @param $uid
	 *            ;//评论者的id @param $buid;//被评论者的id
	 * @param $conId
	 *            ;//被评论的内容id @param $type ;// 被评论类型activity club humor_trends
	 *            photo photo_img record_article
	 * @param $content
	 *            ;//评论内容
	 */
	public void sendMessage(final String uid, final String buid,
			final String conId, final String type, final String contents) {
		MyThreadTool.fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
//				   
//						+ conId + "&type=" + type + "&content=" + contents);
				String content = Utils.getRequest(Constants.BadiUrl
						+ "user_discuss?uid=" + uid + "&buid=" + buid
						+ "&conId=" + conId + "&type=" + type + "&content="
						+ contents);

				if (content != null) {
//					   ("数据是：" + content);
					Results results = Utils.checkResult_NNN(getActivity(),
							content);
					if (results != null && !results.getRetmsg().equals("null")) {
//						   
						try {

							if (results.isRet() == true) {
								handler.sendEmptyMessage(5);
							} else {
								handler.sendEmptyMessage(6);
							}
						} catch (Exception e) {
							// TODO Auto-generated catch block
							   
						}
					} else {
						handler.sendEmptyMessage(3);
					}
				} else {
					handler.sendEmptyMessage(1);
				}

			}
		});
	}

	private View addHead(String path) {
		// TODO Auto-generated method stub
		LayoutInflater inflater = LayoutInflater.from(getActivity());
		View view = inflater.inflate(R.layout.net_img1_img, null);
		ImageView iv = (ImageView) view.findViewById(R.id.img);
		iv.setLayoutParams(new LinearLayout.LayoutParams(DisplayUtil.dip2px(
				getActivity(), 40), DisplayUtil.dip2px(getActivity(), 40)));
		// iv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayou,
		// height));
		iv.setPadding(DisplayUtil.dip2px(getActivity(), 1), 0,
				DisplayUtil.dip2px(getActivity(), 1), 0);

		try {
			ImageLoader.getInstance().displayImage(
					Constants.BadiDownImgUrl + "/" + path, iv, options);
		} catch (Exception e) {
			// TODO: handle exception
		}
		return view;
	}

	private void init(View view) {
		// TODO Auto-generated method stub
		// if (aMap == null) {
		// aMap = mapView.getMap();
		// aMap.setInfoWindowAdapter(this);// 设置自定义InfoWindow样式
		// aMap.setOnMarkerClickListener(this);// 设置点击marker事件监听器
		// }
	}

	/**
	 * 方法必须重写
	 */
	@Override
	public void onResume() {
		super.onResume();
		// mapView.onResume();
	}

	/**
	 * 方法必须重写
	 */
	@Override
	public void onPause() {
		super.onPause();
		// mapView.onPause();
		
	}

	/**
	 * 方法必须重写
	 */
	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		// mapView.onSaveInstanceState(outState);
	}

	/**
	 * 方法必须重写
	 */
	@Override
	public void onDestroy() {
		super.onDestroy();
		// mapView.onDestroy();
		
		//改		
		if (holder.introduce != null) {
			try {
				holder.activity_canjiazhe.removeView(holder.introduce);  
				holder.introduce.removeAllViews(); 
				holder.introduce.destroy();
			} catch (Exception e) {
			
			}
			}
		ImageLoader.getInstance().clearDiscCache();
		ImageLoader.getInstance().clearMemoryCache();


	}

	/**
	 * 查看某个动态的评论列表---get(必需--配合语言)
	 * 
	 * @param $id
	 *            //(必需)需要查看的动态评论ID
	 * @param $type
	 *            //(必需)动态的类型---photo_img：图片，photo：相册，record_article：记录（记），
	 *            humor_trends:心情动态，club：俱乐部，activity：活动
	 * @param $disNum
	 *            //显示的一级评论数量
	 * @param $l
	 *            ;（必需）//zh-cn 为中文简体，zh-tw 中文繁体 en-us 英文
	 */
	private void ShowDisscuss(final String id, final String type,
			final String disNum, String l) {
		Utils.showPrgress(getActivity());
		MyThreadTool.fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				Map<String, Object> map = new HashMap<String, Object>();

				// String content = Utils.sendRequest(map, Constants.BadiUrl
				// + "friends");
				String l = Dialog.getSystemLanguageTypegy(getActivity());
				String content = Utils.getRequest(Constants.BadiUrl_1
						+ "commonality/showDisscuss?id=" + id + "&type=" + type
						+ "&disNum=" + disNum + "&l=" + l);
//				   ();
				// + "&page=" + page + "&pageNum=" + 10);
//				   
				if (content != null) {
					Results results = Utils.checkResult_NNN(getActivity(),
							content);
					if (results != null && !results.getRetmsg().equals("null")) {
//						   
						try {
							discuss = JsonUtil.getEntityByJsonString(
									results.getRetmsg(), Discuss.class);
							// showDisscuss=discuss.getDiscu().get(0);
							// activityReadingModel=JsonUtil.getEntityByJsonString(results.getRetmsg(),
							// ActivityReadingModel.class);
							handler.sendEmptyMessage(4);
						} catch (Exception e) {
							   
						}
					} else {

						handler.sendEmptyMessage(3);
					}
				} else {

					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	/**
	 * 活动阅读---详细页面--仅适用于线下活动--get(必需--配合语言)
	 * 
	 * @param $actId
	 *            //(必需)活动ID--6
	 * @param $uid
	 *            //(必需)访问用户ID
	 * @param $l
	 *            ;（必需）//zh-cn 为中文简体，zh-tw 中文繁体 en-us 英文
	 */
	private void ShowActivity() {
		Utils.showPrgress(getActivity());
		MyThreadTool.fixedThreadPool.execute(new Runnable() {
			@Override
			public void run() {
				Map<String, Object> map = new HashMap<String, Object>();

				// String content = Utils.sendRequest(map, Constants.BadiUrl
				// + "friends");
				String l = Dialog.getSystemLanguageTypegy(getActivity());
				String uid = Utils.getUid(getActivity());
				String content = Utils.getRequest(Constants.BadiUrl_1
						+ "activity/showActivity?actId=" + actId + "&uid="
						+ uid + "&l=" + l);
//				   
//						+ "activity/showActivity?actId=" + actId + "&uid="
//						+ uid + "&l=" + l);
//				   ();
				// + "&page=" + page + "&pageNum=" + 10);
//				   
				if (content != null) {
					Results results = Utils.checkResult_NNN(getActivity(),
							content);
					if (results != null && !results.getRetmsg().equals("null")) {
//						   
						try {
							activityReadingModel = JsonUtil
									.getEntityByJsonString(results.getRetmsg(),
											ActivityReadingModel.class);
							Thread.sleep(500);
							handler.sendEmptyMessage(2);
						} catch (Exception e) {
							   
						}
					} else {
						handler.sendEmptyMessage(3);
					}
				} else {
					handler.sendEmptyMessage(1);
				}
			}
		});
	}

	/**
	 * 这里显示评论的
	 */
	private void initDissCussView() {
		gyAdapter = new PinLunGYAdapter(getActivity(), discuss, actId,
				"activity", activityReadingModel.getUid(), holder.send_content,
				holder.send);
		gyAdapter.setOnRefreshPingLunInterface(new PinLunInterface() {

			@Override
			public void DeletePingLunRefresh() {
				// TODO Auto-generated method stub
				ShowActivity();
			}
		});
		holder.listview_pinlun.setAdapter(gyAdapter);

	}

	public static ActivityReadingOffLineFragment getInstance() {
		if (fragment == null) {
			return new ActivityReadingOffLineFragment();
		}
		return fragment;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub

	}

	/**
	 * 
	 * 设置标题
	 * 
	 * @param set
	 */
	public void getData(setActivityView set) {
		set.getData(activityReadingModel);
	}

	// /**松岛枫
	// * 判断是
	// */
	// public void ShowOrGoneBottomButton()

	public interface setActivityView {
		void getData(ActivityReadingModel activityModel);
	}

	/**
	 * 点赞 接口名称 praise_operate 用户的点赞人的id 提交方式$GET
	 * 
	 * @param $uid
	 *            ;//点赞人的id
	 * @param $nid
	 *            ;//被操作内容的Id
	 * @param $nuid
	 *            ;//内容所属人id
	 * @param $type赞的类型
	 *            （record_article，club，humor_trends，photo，activity）
	 * @param hander
	 *            ;
	 * @param Success
	 *            ;成功
	 * @param defalt
	 *            ;失败
	 */
	public void dianzan(final Context context, final String uid,
			final String nid, final String nuid, final String type,
			final int Success, final int defalt) {
		new Thread(new Runnable() {

			@Override
			public void run() {
				String content = Utils.getRequest(Constants.BadiUrl
						+ "praise_operate?uid=" + uid + "&nid=" + nid
						+ "&nuid=" + nuid + "&type=" + type);
//				   
//						+ "type=" + type);
//				   ("数据是：" + content);
				if (content != null) {
//					   ("数据是：" + content);
					Results results = Utils.checkResult_NNN(context, content);
					if (results != null && !results.getRetmsg().equals("null")) {
//						   
						try {

							if (results.isRet()) {

								handler.sendEmptyMessage(Success);
							} else
								handler.sendEmptyMessage(defalt);
						} catch (Exception e) {
							   
						}
					} else {
						handler.sendEmptyMessage(1);
					}
				} else {
					handler.sendEmptyMessage(1);
				}
			}
		}).start();

	}

	// @Override
	// public View getInfoContents(Marker arg0) {
	// // TODO Auto-generated method stub
	// return null;
	// }
	//
	// @Override
	// public View getInfoWindow(Marker marker) {
	// // TODO Auto-generated method stub
	// View infoWindow = getActivity().getLayoutInflater().inflate(
	// R.layout.custom_info_window, null);
	//
	// render(marker, infoWindow);
	// return infoWindow;
	// }

	private void render(Marker marker, View view) {
		// TODO Auto-generated method stub
		ImageView img = (ImageView) view.findViewById(R.id.img);
		String p = marker.getTitle();
//		   
		int pos = Integer.parseInt(marker.getTitle().toString());
		try {
			// VolleyTools.displayImageByNetworkImageView(
			// getActivity(),
			// Constants.BadiDownImgUrl + "/"
			// + activityReadingModel.getImage(), img);
			ImageLoader.getInstance().displayImage(
					Constants.BadiDownImgUrl + "/"
							+ activityReadingModel.getImage(), img, options);
		} catch (Exception e) {
		}
		// 数量
		TextView imgNum = (TextView) view.findViewById(R.id.imgNum);
		imgNum.setText("");
		// 地址
		TextView address = (TextView) view.findViewById(R.id.address);
		address.setText("" + activityReadingModel.getAddress());
		// 内容
		TextView info = (TextView) view.findViewById(R.id.info);
		info.setText("" + activityReadingModel.getOrganization_introduce());

		// String title = marker.getTitle();
		// TextView titleUi = ((TextView) view.findViewById(R.id.title));
		// if (title != null) {
		// SpannableString titleText = new SpannableString(title);
		// titleText.setSpan(new ForegroundColorSpan(Color.RED), 0,
		// titleText.length(), 0);
		// titleUi.setTextSize(15);
		// titleUi.setText(titleText);
		//
		// } else {
		// titleUi.setText("");
		// }
	}

	// //打开软键盘
	// public void OpenKey()
	// {
	// EditTextTools.ConsultingEvaluation(holder.send_content);
	// }

	// @Override
	// public void onInfoWindowClick(Marker arg0) {
	// // TODO Auto-generated method stub
	//
	// }
	//
	// @Override
	// public boolean onMarkerClick(Marker arg0) {
	// // TODO Auto-generated method stub
	// return false;
	// }
	public void getSend_Content(getEditText get) {
		get.getEditText(holder.send_content);

	}

	public interface getEditText {
		void getEditText(EditText send_content);
	}
}
